
//Friend code!
names = [];
ftables = [];
jsids = [];
pstat = [];
reqs = [];
function pf (name,table,jsid,status,isplayer) {
	//function to manage the arrays
	for (id=0;id<names.length;id++) 
	if (name==names[id]) {
	   //id = names.indexOf(name);
	   names.splice(id,1);
	   ftables.splice(id,1);
	   jsids.splice(id,1);
	   pstat.splice(id,1);
	}
	if (status==2 || status=="2") {
		//alert(name+" removed");
		build_html();
		return;
	}
	names.push(name);
	ftables.push(table);
	jsids.push(jsid);
	pstat.push(isplayer);
	build_html();
}
function pfreq (name) {
	//function to manage the arrays
	if (reqs.indexOf(name)!=-1) {
	   //reqs.remove(name);
	   return;
	}
	reqs.push(name);
	build_html();
}
function build_html() {
	h_flist = "<button onclick='showinvite();'>Invite Friends</button><br>";
	h_frlist = "";
	for (x=0;x<names.length;x++) {
		//build list to goto div "flist"
		if (pstat[x]==1) playstr = 'playing';
			else playstr = 'watching';
		h_flist+='<div class="buddy"><span class="buddyuser" onclick="ddm_replace(this, event, menu_buddy, \'120px\')" id="buddy"'+names[x]+'>'+names[x]+'</span> '+playstr+' <a href="#switch" onclick="switchBoards('+jsids[x]+');">'+ftables[x]+'</a></div>';
	}
	for (x=0;x<reqs.length;x++) {
	 	//build list to goto div "frlist"
	 	if (names.indexOf(reqs[x])==-1)
		h_frlist+='<div class="buddyreq" onclick="ddm_replace(this, event, menu_request, \'120px\')" id="buddyreq"'+reqs[x]+'>'+reqs[x]+'</div>';
	}
	document.getElementById('flist').innerHTML=h_flist;
	document.getElementById('frlist').innerHTML=h_frlist;

}

function remove_friend(name) {
	pf (name,"",0,2,0);
	Tracker.removeFriend(name);
	reqs.splice(reqs.indexOf(name),1);
}
function approve_req(name) {
	Tracker.sendFriendReq(name);
}

